#!/usr/bin/env bash
#
# Perform full build and runs the tests.
# Prerequisite: workspace with dependencies installed, see bootstrap.sh

# Fail if any commands fails
set -e

echo "#### Generating files... ####"
tools/generate-files

echo "#### Building... ####"
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
make -Cbuild -j12 tests TrezorCryptoTests

if [ -x "$(command -v clang-tidy)" ]; then
    echo "#### Linting... ####"
    tools/lint
fi

echo "#### Running trezor-crypto tests... ####"
export CK_TIMEOUT_MULTIPLIER=4
build/trezor-crypto/crypto/tests/TrezorCryptoTests

echo "#### Running unit tests... ####"
ROOT="`dirname \"$0\"`/.."
TESTS_ROOT="`(cd \"$ROOT/tests\" && pwd)`"
FILTER="*"
build/tests/tests "$TESTS_ROOT" --gtest_filter="$FILTER"
